home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / AEikHandleTemplate.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  35.3 KB  |  1,208 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //    Alias|Wavefront Script File
  19. //
  20. //    Creation Date:    May 29, 1997
  21. //    Author:            ajp
  22. //
  23. //    Procedure Name:
  24. //    AEikHandleTemplate
  25. //
  26. //    Description Name;
  27. //    Creates the attribute editor controls for the ikHandle node
  28. //
  29. //    Input Value:
  30. //    nodeName
  31. //
  32. //    Output Value:
  33. //    None
  34. //
  35.  
  36. global string $gAEIKHandleMenus[];
  37.  
  38. //    these arrays are used to keep track of the
  39. //    "World Up" and "World Up End" widgets in ik handle
  40. //    Attribute Editors.  Because users can tear off AE
  41. //    panels, there can be multiple such controls in 
  42. //    existence at once.
  43. //
  44. global string $gAEikWorldUpWidgets[];
  45. global string $gAEikWorldUp2Widgets[];
  46.  
  47.  
  48. proc string getCurrentikHandleMenu(string $nodeName)
  49. {
  50.     global string $gAEIKHandleMenus[];
  51.  
  52.     // look for correct parent
  53.     //
  54.     string $curParent = `setParent -q`;
  55.     int $index = -1;
  56.     int $i;
  57.     for ($i = 0; $i < size($gAEIKHandleMenus); $i += 3 ) {
  58.         if ( $curParent == $gAEIKHandleMenus[$i+1] ) {
  59.             $index = $i+2;
  60.             break;
  61.         }
  62.     }
  63.     string $menu = "ikSolverOptionMenu";
  64.     if ($index != -1) {
  65.         $menu = $gAEIKHandleMenus[$index];
  66.         $gAEIKHandleMenus[$index-2] = $nodeName;
  67.     }
  68.     return $menu;
  69. }
  70.  
  71. global proc checkIKHandleIKBlendEnable( string $nodeName )
  72. {
  73.     int $enable = `getAttr ($nodeName+".ikFkManipulation")`;
  74.     editorTemplate -dimControl $nodeName "snapEnable" $enable;
  75. }
  76.  
  77. global proc checkIkHandleSolverEnable ( string $nodeName )
  78. {
  79.     global string $gAEIKHandleMenus[];
  80.  
  81.     string $nodeAttr = $nodeName + ".ikBlend";
  82.     float $ikBlend = `getAttr $nodeAttr`;
  83.     int $solverEnable = ($ikBlend != 0.0);
  84.  
  85.     // loop through the ikHandle AEs and dim the appropriate
  86.     // optionMenus
  87.     //
  88.     int $i;
  89.     for ( $i = 0; $i < size($gAEIKHandleMenus); $i += 3 ) {
  90.         if ( $gAEIKHandleMenus[$i] == $nodeName
  91.             && `optionMenuGrp -exists $gAEIKHandleMenus[$i+2]` )
  92.         {
  93.             if ($solverEnable) {
  94.                 optionMenuGrp -e -en 1 $gAEIKHandleMenus[$i+2];
  95.             } else {
  96.                 optionMenuGrp -e -en 0 $gAEIKHandleMenus[$i+2];
  97.             } 
  98.         }
  99.     }
  100.  
  101.     string $solver[] = `listConnections ( $nodeName + ".ikSolver" )`;
  102.     string $solverType = `objectType $solver[0]`;
  103.     
  104.     switch ($solverType){
  105.         case "ikRPsolver":
  106.             editorTemplate -dimControl $nodeName "poleVector" false;
  107.             editorTemplate -dimControl $nodeName "twist" false;
  108.             editorTemplate -dimControl $nodeName "offset" true;
  109.             editorTemplate -dimControl $nodeName "roll" true;
  110.             editorTemplate -dimControl $nodeName "rootOnCurve" true;
  111.             editorTemplate -dimControl $nodeName "rootTwistMode" true;
  112.             editorTemplate -dimControl $nodeName "twistType" true;
  113.             break;
  114.         case "ikSCsolver":
  115.         case "ikMCsolver":
  116.             editorTemplate -dimControl $nodeName "poleVector" true;
  117.             editorTemplate -dimControl $nodeName "twist" true;
  118.             editorTemplate -dimControl $nodeName "offset" true;
  119.             editorTemplate -dimControl $nodeName "roll" true;
  120.             editorTemplate -dimControl $nodeName "rootOnCurve" true;
  121.             editorTemplate -dimControl $nodeName "rootTwistMode" true;
  122.             editorTemplate -dimControl $nodeName "twistType" true;
  123.             break;
  124.         case "ikSplineSolver":
  125.             editorTemplate -dimControl $nodeName "poleVector" true;
  126.             editorTemplate -dimControl $nodeName "twist" false;
  127.             editorTemplate -dimControl $nodeName "offset" false;
  128.             editorTemplate -dimControl $nodeName "roll" false;
  129.             editorTemplate -dimControl $nodeName "rootOnCurve" false;
  130.             editorTemplate -dimControl $nodeName "rootTwistMode" false;
  131.             editorTemplate -dimControl $nodeName "twistType" false;
  132.             break;
  133.         default:
  134.             editorTemplate -dimControl $nodeName "poleVector" false;
  135.             editorTemplate -dimControl $nodeName "twist" false;
  136.             editorTemplate -dimControl $nodeName "offset" false;
  137.             editorTemplate -dimControl $nodeName "roll" false;
  138.             editorTemplate -dimControl $nodeName "rootOnCurve" false;
  139.             editorTemplate -dimControl $nodeName "rootTwistMode" false;
  140.             editorTemplate -dimControl $nodeName "twistType" false;
  141.             break;
  142.     }
  143.  
  144. }
  145.  
  146.  
  147. global proc AEupdateSolverMenu(string $menu, string $nodeName)
  148. {
  149.  
  150.     setParent $menu;
  151.  
  152.     // loop through the menu items to check that one of them
  153.     // matches the current solver
  154.     //
  155.     int $i;
  156.     string $plug = $nodeName + ".ikSolver";
  157.     string $connections[] = `listConnections $plug`;
  158.     string $currentSolver = $connections[0];
  159.     int $numMenuItems = `optionMenuGrp -q -ni $menu`;
  160.     string $menuItems[] = `optionMenuGrp -q -ill $menu`;
  161.     for ( $i = 0; $i < $numMenuItems; $i++ ) {
  162.         if ( $menuItems[$i] == $currentSolver ) {
  163.             optionMenuGrp -e -v $currentSolver $menu;
  164.             checkIkHandleSolverEnable $nodeName;
  165.             return;
  166.         }
  167.     }
  168.  
  169.     // if we've made it this far, the currentSolver doesn't
  170.     // exist in the optionMenu - we need to rebuild the
  171.     // optionMenuGrp
  172.     //
  173.  
  174.     // get the current solver type
  175.     //
  176.     string $solverType = `objectType $currentSolver`;
  177.  
  178.     // get a list of all solvers
  179.     //
  180.     string $solverList[]= `ikSystem -q -ls`;
  181.     int $sListSize = size($solverList);
  182.  
  183.     // get only the solvers we're interested in
  184.     //
  185.     string $relevantSolvers[];
  186.     if ($solverType == "ikSplineSolver") {
  187.         for ($i = 0; $i < $sListSize; $i++) {
  188.             if (`objectType $solverList[$i]` == "ikSplineSolver") {
  189.                 $relevantSolvers[size($relevantSolvers)] = $solverList[$i];
  190.             }
  191.         }
  192.     } else {
  193.         for ($i = 0; $i < $sListSize; $i++) {
  194.             if (`objectType $solverList[$i]` != "ikSplineSolver") {
  195.                 $relevantSolvers[size($relevantSolvers)] = $solverList[$i];
  196.             }
  197.         }
  198.     }
  199.     int $rListSize = size($relevantSolvers);
  200.  
  201.     // rebuild the menuItems now
  202.     //
  203.     setParent -m ($menu+"|OptionMenu");
  204.     string $menuItemName = "AEikSolverItem";
  205.     if ( $rListSize <= $numMenuItems ) {
  206.  
  207.         // replace existing menu items
  208.         //
  209.         for ( $i = 0; $i < $rListSize; $i++ ) {
  210.             menuItem -e -l $relevantSolvers[$i] ($menuItemName+$i);
  211.         }
  212.  
  213.         //  delete unused menu items
  214.         //
  215.         for ( $i = $rListSize; $i < $numMenuItems; $i++) {
  216.             deleteUI -mi ($menuItemName+$i);
  217.         }
  218.  
  219.     } else {
  220.  
  221.         // replace existing menu items
  222.         //
  223.         for ( $i = 0; $i < $numMenuItems; $i++ ) {
  224.             menuItem -e -l $relevantSolvers[$i] ($menuItemName+$i);
  225.         }
  226.  
  227.         // build new menu items
  228.         //
  229.         for ( $i = $numMenuItems; $i < $rListSize; $i++) {
  230.             menuItem -l $relevantSolvers[$i] ($menuItemName+$i);
  231.         }
  232.  
  233.     }
  234.  
  235.     optionMenuGrp -e -v $currentSolver $menu;
  236.     checkIkHandleSolverEnable $nodeName;
  237. }
  238.  
  239. global proc AEikUpdateSolver(string $menu, string $nodeName)
  240. {
  241.     setParent $menu;
  242.     ikHandle -e -solver `optionMenuGrp -q -v $menu` $nodeName;
  243.     checkIkHandleSolverEnable $nodeName;
  244. }
  245.  
  246. global proc AEikHandleSolverNew(string $ikSolver)
  247. {
  248.     global string $gAEIKHandleMenus[];
  249.  
  250.     // get the nodeName
  251.     //
  252.     string $buffer[];
  253.     tokenize($ikSolver,".|",$buffer);
  254.     string $nodeName = $buffer[0];
  255.  
  256.     int $numIKHandleAEs = size($gAEIKHandleMenus);
  257.     $gAEIKHandleMenus[$numIKHandleAEs] = $nodeName;
  258.     $gAEIKHandleMenus[$numIKHandleAEs+1] = `setParent -q`;
  259.  
  260.     // build the optionMenuGrp
  261.     //
  262.     string $menu = `optionMenuGrp -l "IK Solver" ikSolverOptionMenu`;
  263.     optionMenuGrp -e
  264.         -cc ("AEikUpdateSolver " + $menu + " " + $nodeName ) 
  265.         $menu;
  266.  
  267.     $gAEIKHandleMenus[$numIKHandleAEs+2] = $menu;
  268.  
  269.     // only interested if there are solvers attached
  270.     //
  271.     string $solver[];
  272.     if (!catch ($solver = `listConnections $ikSolver`)) {
  273.  
  274.         int $i;
  275.  
  276.         // get all the solvers in the system
  277.         //
  278.         string $solverList[] = `ikSystem -q -ls`;
  279.         int $sListSize = size($solverList);
  280.  
  281.         // get the current solver type
  282.         //
  283.         string $solverType = `objectType $solver[0]`;
  284.  
  285.         // get only the solvers we're interested in
  286.         //
  287.         string $relevantSolvers[];
  288.         if ($solverType == "ikSplineSolver") {
  289.             for ($i = 0; $i < $sListSize; $i++) {
  290.                 if (`objectType $solverList[$i]` == "ikSplineSolver") {
  291.                     $relevantSolvers[size($relevantSolvers)] = $solverList[$i];
  292.                 }
  293.             }
  294.         } else {
  295.             for ($i = 0; $i < $sListSize; $i++) {
  296.                 if (`objectType $solverList[$i]` != "ikSplineSolver") {
  297.                     $relevantSolvers[size($relevantSolvers)] = $solverList[$i];
  298.                 }
  299.             }
  300.         }
  301.  
  302.         // build the menuItems
  303.         //
  304.         string $menuItemName = "AEikSolverItem";
  305.         for ($i = 0; $i < size($relevantSolvers); $i++ ) {
  306.             menuItem -l $relevantSolvers[$i] ($menuItemName+$i);
  307.         }
  308.  
  309.         setParent -m ..;
  310.  
  311.         // build the callback mechanisms
  312.         //
  313.         optionMenuGrp -e -v $solver[0] $menu;
  314.         string $cmd = "AEupdateSolverMenu " + $menu + " " + $nodeName;
  315.         scriptJob -rp -p $menu -attributeChange $ikSolver $cmd;
  316.  
  317.         checkIkHandleSolverEnable $nodeName;
  318.     }
  319. }
  320.  
  321.  
  322. global proc AEikHandleSolverReplace(string $ikSolver)
  323. {
  324.     // get the nodeName
  325.     //
  326.     string $buffer[];
  327.     tokenize($ikSolver,".|",$buffer);
  328.     string $nodeName = $buffer[0];
  329.  
  330.     // get parent
  331.     string $menu = getCurrentikHandleMenu( $nodeName );
  332.     string $menuItemName = "AEikSolverItem";
  333.  
  334.     // only need to worry about the replace if a solver is connected
  335.     //
  336.     string $solver[];
  337.     if (!catch ($solver = `listConnections $ikSolver`)) {
  338.  
  339.         // get the current solver type
  340.         //
  341.         string $solverType = `objectType $solver[0]`;
  342.  
  343.         // get a list of all solvers
  344.         //
  345.         string $solverList[]= `ikSystem -q -ls`;
  346.         int $sListSize = size($solverList);
  347.  
  348.         // get only the solvers we're interested in
  349.         //
  350.         string $relevantSolvers[];
  351.         if ($solverType == "ikSplineSolver") {
  352.             for ($i = 0; $i < $sListSize; $i++) {
  353.                 if (`objectType $solverList[$i]` == "ikSplineSolver") {
  354.                     $relevantSolvers[size($relevantSolvers)] = $solverList[$i];
  355.                 }
  356.             }
  357.         } else {
  358.             for ($i = 0; $i < $sListSize; $i++) {
  359.                 if (`objectType $solverList[$i]` != "ikSplineSolver") {
  360.                     $relevantSolvers[size($relevantSolvers)] = $solverList[$i];
  361.                 }
  362.             }
  363.         }
  364.         int $rListSize = size($relevantSolvers);
  365.  
  366.         // get the number of items currently in the optionMenu
  367.         //
  368.         int $mListSize = `optionMenuGrp -q -ni $menu`;
  369.  
  370.         int $i;
  371.  
  372.         // rebuild the menuItems now
  373.         //
  374.         setParent -m ($menu+"|OptionMenu");
  375.         if ( $rListSize <= $mListSize) {
  376.  
  377.             // replace existing menu items
  378.             //
  379.             for ( $i = 0; $i < $rListSize; $i++ ) {
  380.                 menuItem -e -l $relevantSolvers[$i] ($menuItemName+$i);
  381.             }
  382.  
  383.             //  delete unused menu items
  384.             //
  385.             for ( $i = $rListSize; $i < $mListSize; $i++) {
  386.                 deleteUI -mi ($menuItemName+$i);
  387.             }
  388.  
  389.         } else {
  390.  
  391.             // replace existing menu items
  392.             //
  393.             for ( $i = 0; $i < $mListSize; $i++ ) {
  394.                 menuItem -e -l $relevantSolvers[$i] ($menuItemName+$i);
  395.             }
  396.  
  397.             // build new menu items
  398.             //
  399.             for ( $i = $mListSize; $i < $rListSize; $i++) {
  400.                 menuItem -l $relevantSolvers[$i] ($menuItemName+$i);
  401.             }
  402.  
  403.         }
  404.  
  405.         setParent -m ..;
  406.  
  407.         // update the optionMenuGrp and callback mechanisms
  408.         optionMenuGrp -e
  409.             -v $solver[0]
  410.             -cc ("AEikUpdateSolver "+$menu+" "+$nodeName)
  411.             $menu;
  412.         string $cmd = "AEupdateSolverMenu " + $menu + " " + $nodeName;
  413.         scriptJob -rp -p $menu -attributeChange $ikSolver $cmd;
  414.  
  415.         checkIkHandleSolverEnable $nodeName;
  416.     }
  417. }
  418.  
  419. //=====================================================================
  420. //
  421. //    Advanced Twist Controls code:
  422. //
  423. //        This section contains routines that maintain the UI for
  424. //        the Advanced Twist controls for spline IK handles.  This
  425. //        feature is controlled by dynamic attributes on the ik handle
  426. //        node.  A button is provided in the AE to add these dynamic
  427. //        attributes to the node, and to add the appropriate controls
  428. //        to the AE.
  429. //
  430. //        Most of the controls are straightforward numeric or enum values
  431. //        that drive the chain twisting, with the exception of the
  432. //        "World Up Object" and "World Up Object 2" controls.  The spline
  433. //        handle allows the user to specify target objects for the start
  434. //        and end of the joint chain to orient themselves against.  Internally,
  435. //        this is done via a matrix connection - the object's object->world
  436. //        matrix is connected to a matrix attribute on the ik handle.  The 
  437. //        controls presented in the AE for these attributes are text boxes
  438. //        into which the user types the names of the desired target objects.
  439. //        Behind the scenes, the appropriate matrix attribute connections are
  440. //        established.  Much of the code in this section is devoted to 
  441. //        maintaining these custom controls.  It is further complicated by the
  442. //        fact that multiple Attribute Editors can be in existenace at any
  443. //        time, so we must make sure that all AEs stay in sync with their
  444. //        corresponding IK handles.
  445. //
  446. //        The routines in this section are:
  447. //
  448. //        Part 1: Routines for managing dynamic attrs on the ik handle:
  449. //        
  450. //            addAdvancedTwistAttrs()        
  451. //                - adds dynamic attrs to ik handle node
  452. //
  453. //
  454. //        Part 2: Routines for maintaining the button that the user presses
  455. //                to add the new controls to the ik handle
  456. //
  457. //            AEikTwistAddAttrNew()         
  458. //                - custom control proc, creates button to 
  459. //                  add dynamic attributes
  460. //
  461. //            AEikTwistAttrReplace()         
  462. //                - custom control proc, updates dynamic attr
  463. //                  button when the AE changes nodes
  464. //    
  465. //
  466. //        Part 3: Routines for maintaining the World Up Object and
  467. //                World Up Object End custom controls.
  468. //
  469. //            AEikWorldUpObjectNew() 
  470. //                - creates the World Up Object control
  471. //
  472. //            AEikWorldUpObjectReplace()
  473. //                - updates the World Up Object control when the AE
  474. //                  shifts focus
  475. //
  476. //            AEikWorldUpObject2New() 
  477. //                - creates the World Up Object 2 control
  478. //
  479. //            AEikWorldUpObject2Replace()
  480. //                - updates the World Up Object 2 control when the AE
  481. //                  shifts focus
  482. //
  483. //            AEikWorldUpObjectControlProc()
  484. //                - called whenever a user enters the name of an object
  485. //                  into the World Up Object or World Up Object 2 text
  486. //                  boxes
  487. //
  488. //            getIkWorldUpObject()
  489. //                - utility function to retrieve the name of the object
  490. //                  currently driving either the World Up Object or
  491. //                  World Up Object 2 attributes
  492. //
  493. //            updateIkWorldUpObject()
  494. //                - updates one of the World Up Object/World Up Object 2
  495. //                  controls when the AE shifts focus
  496. //
  497. //            twistControlDimUI()
  498. //            worldUpTypeDimUI()
  499. //            twistValueTypeDimUI()
  500. //            setStateIkWorldUpObject()
  501. //                - routines for dimming various pieces of UI when the 
  502. //                  "Enabled Twist Controls", "World Up Type", and
  503. //                  "Twist Value Type" values are changed.
  504. //
  505. //=====================================================================
  506.  
  507.  
  508. //=====================================================================
  509. //    Part 1: Routines for managing dynamic attributes on ik handle.
  510. //=====================================================================
  511.  
  512. global proc addTwistControlAttrs( string $nodeName )
  513. {
  514.     int $alreadyExist = ikSplineHandleTwistControls( $nodeName, "query" );
  515.     if( !$alreadyExist )
  516.     {
  517.         ikSplineHandleTwistControls( $nodeName, "add" );
  518.     }
  519. }
  520.  
  521. //=====================================================================
  522. //    End Part 1.
  523. //=====================================================================
  524.  
  525.  
  526. //=====================================================================
  527. //    Part 2: Routines for managing the "Add Advanced Twist Controls"
  528. //            AE button.
  529. //=====================================================================
  530.  
  531. global proc AEikTwistAddAttrNew ( string $attr )
  532. {
  533.     global int $gTextColumnWidthIndex;
  534.  
  535.     string $nodeName[];
  536.     tokenize($attr, ".", $nodeName);
  537.  
  538.  
  539.     setUITemplate -pst attributeEditorPresetsTemplate;
  540.     rowLayout -nc 2 -columnWidth 1 $gTextColumnWidthIndex
  541.             -columnWidth 2 225
  542.             -columnAttach 2 both 0
  543.             -columnAttach 1 right 5;
  544.         text -l "Add Attributes For" -vis 0;
  545.         button -l "Add Advanced Twist Control Attributes"
  546.             -c ("addTwistControlAttrs " + $nodeName[0] )
  547.             addIkTwistAttrButton;
  548.         setParent ..;
  549.     setUITemplate -ppt;
  550. }
  551.  
  552. global proc AEikTwistAttrReplace ( string $attr )
  553. {
  554.     string $nodeName[];
  555.     tokenize($attr, ".", $nodeName);
  556.  
  557.     button -e -c ("addTwistControlAttrs " + $nodeName[0] )
  558.         addIkTwistAttrButton;
  559. }
  560.  
  561. //=====================================================================
  562. //    End Part 2.
  563. //=====================================================================
  564.  
  565.  
  566. //=====================================================================
  567. //    Part 3: Routines for managing World Up Object and World Up Object 2
  568. //            controls in the ik handle AE.
  569. //=====================================================================
  570.  
  571. global proc AEikWorldUpObjectNew( string $plug )
  572. //
  573. //    Description:
  574. //
  575. //        Creates a new "World Up Object" text box control
  576. //        in the IK handle AE.
  577. //
  578. {
  579.     //    There may be many AEs in existence, and each one will
  580.     //    have a text box for displaying the name of the World Up
  581.     //    Object.  This array keeps track of all such controls
  582.     //    currently in existence.
  583.     //
  584.     //    The array contains 3 elements for each control:
  585.     //    
  586.     //        1) the name of the ik handle node
  587.     //        2) the name of the UI parent under which the text
  588.     //           box lives
  589.     //        3) the name of the text box control
  590.     //
  591.     //    When a text control is updated, we use this array to 
  592.     //    determine which ik handle that control is referring to.
  593.     //
  594.     global string $gAEikWorldUpWidgets[];
  595.  
  596.     //    get the node name
  597.     //
  598.     string $buffer[];
  599.     tokenize($plug,".|",$buffer);
  600.     string $nodeName = $buffer[0];
  601.  
  602.     // save the node name and the parent info in the global
  603.     // string array
  604.     //
  605.     int $numIkAEs = size($gAEikWorldUpWidgets);
  606.     $gAEikWorldUpWidgets[$numIkAEs] = $nodeName;
  607.     $gAEikWorldUpWidgets[$numIkAEs+1] = `setParent -q`;
  608.  
  609.     //    create the textFieldGrp
  610.     //
  611.     setUITemplate -pst attributeEditorTemplate;
  612.     string $worldUpObjectControl =
  613.         `textFieldGrp -vis 0 -l "World Up Object" AEikWorldUpObjectField`;
  614.  
  615.     //    save the control for possible later reuse
  616.     //
  617.     $gAEikWorldUpWidgets[$numIkAEs+2] = $worldUpObjectControl;
  618.  
  619.     setUITemplate -ppt;
  620.  
  621.     //    synchronize the control with the current state of the ik handle
  622.     //
  623.     updateIkWorldUpObject( $nodeName, $plug, $worldUpObjectControl );
  624. }
  625.  
  626. global proc AEikWorldUpObject2New( string $plug )
  627. //
  628. //    Description:
  629. //
  630. //        Same as AEikWorldUpObjectNew, but creates a control for
  631. //        the World Up Object 2 attribute.  
  632. //
  633. {
  634.     global string $gAEikWorldUp2Widgets[];
  635.  
  636.     //    get the node name
  637.     //
  638.     string $buffer[];
  639.     tokenize($plug,".|",$buffer);
  640.     string $nodeName = $buffer[0];
  641.  
  642.     // save the node name and the parent info in the global
  643.     // string array
  644.     //
  645.     int $numIkAEs = size($gAEikWorldUp2Widgets);
  646.     $gAEikWorldUp2Widgets[$numIkAEs] = $nodeName;
  647.     $gAEikWorldUp2Widgets[$numIkAEs+1] = `setParent -q`;
  648.  
  649.     //    create the textFieldGrp
  650.     //
  651.     setUITemplate -pst attributeEditorTemplate;
  652.  
  653.     string $worldUpObjectControl =
  654.         `textFieldGrp -vis 0 -l "World Up Object 2" AEikWorldUpObject2Field`;
  655.  
  656.     //    save the control for possible later reuse
  657.     //
  658.     $gAEikWorldUp2Widgets[$numIkAEs+2] = $worldUpObjectControl;
  659.  
  660.     setUITemplate -ppt;
  661.  
  662.     //    synchronize the control with the current state of the ik handle
  663.     //
  664.     updateIkWorldUpObject( $nodeName, $plug, $worldUpObjectControl );
  665. }
  666.  
  667.  
  668. global proc AEikWorldUpObjectReplace( string $plug )
  669. //
  670. //    Description:
  671. //
  672. //        Updates the World Up Object AE control when the AE
  673. //        shifts focus to another ik handle node.
  674. //
  675. {
  676.     global string $gAEikWorldUpWidgets[];
  677.  
  678.     //    get the node name
  679.     //
  680.     string $buffer[];
  681.     tokenize($plug,".|",$buffer);
  682.     string $nodeName = $buffer[0];
  683.  
  684.     //    if there is already a control created for this
  685.     //    AE window, then find it in the array (we search 
  686.     //    using the name of the UI parent for the control).
  687.     //    Such a control must exist, but we still make sure
  688.     //    that we actually find it.
  689.     //
  690.     string $curParent = `setParent -q`;
  691.     int $index = -1;
  692.     int $i;
  693.     for ( $i = 0; $i < size($gAEikWorldUpWidgets); $i += 3 ) 
  694.     {
  695.         if ( $curParent == $gAEikWorldUpWidgets[$i+1] )
  696.         {
  697.             $index = $i;
  698.             break;
  699.         }
  700.     }
  701.  
  702.     //    update the entry in the array, as this control is now
  703.     //    referring to a different node
  704.     //
  705.     string $worldUpObjectControl = "AEikWorldUpObjectField";
  706.     if ($index != -1)
  707.     {
  708.         $gAEikWorldUpWidgets[$index] = $nodeName;
  709.         $worldUpObjectControl = $gAEikWorldUpWidgets[$index+2];
  710.     }
  711.  
  712.     //    synchronize the control with the current state of the node
  713.     //
  714.     updateIkWorldUpObject( $nodeName, $plug, $worldUpObjectControl );
  715. }
  716.  
  717. global proc AEikWorldUpObject2Replace( string $plug )
  718. //
  719. //    Description:
  720. //
  721. //        Same as above, but for the World Up Object 2 attribute.
  722. //
  723. {
  724.     global string $gAEikWorldUp2Widgets[];
  725.  
  726.     //    get the node name
  727.     //
  728.     string $buffer[];
  729.     tokenize($plug,".|",$buffer);
  730.     string $nodeName = $buffer[0];
  731.  
  732.     //    if there is already a control created for this
  733.     //    AE window, then find it in the array (we search 
  734.     //    using the name of the UI parent for the control).
  735.     //    Such a control must exist, but we still make sure
  736.     //    that we actually find it.
  737.     //
  738.     string $curParent = `setParent -q`;
  739.     int $index = -1;
  740.     int $i;
  741.     for ( $i = 0; $i < size($gAEikWorldUp2Widgets); $i += 3 ) 
  742.     {
  743.         if ( $curParent == $gAEikWorldUp2Widgets[$i+1] )
  744.         {
  745.             $index = $i;
  746.             break;
  747.         }
  748.     }
  749.  
  750.     //    update the entry in the array, as this control is now
  751.     //    referring to a different node
  752.     //
  753.     string $worldUpObjectControl = "AEikWorldUpObject2Field";
  754.     if ($index != -1)
  755.     {
  756.         $gAEikWorldUp2Widgets[$index] = $nodeName;
  757.         $worldUpObjectControl = $gAEikWorldUp2Widgets[$index+2];
  758.     }
  759.  
  760.     //    synchronize the control with the current state of the node
  761.     //
  762.     updateIkWorldUpObject( $nodeName, $plug, $worldUpObjectControl );
  763. }
  764.  
  765.  
  766. global proc AEikWorldUpObjectControlProc(string $plug,
  767.                                          string $widget)
  768. //
  769. //    Description:
  770. //
  771. //        Gets called when the contents of a World Up Object
  772. //        or World Up Object 2 text box control in the AE
  773. //        is modified.  This code must then go find the
  774. //        specified object and connect its object->world
  775. //        matrix to the ik handle's appropriate matrix
  776. //        attribute.
  777. //
  778. {
  779.     //    get the current value of the widget
  780.     //
  781.     string $value = `textFieldGrp -q -text $widget`;
  782.  
  783.     //    find the specified object
  784.     //
  785.     string $found[] = `ls $value`;
  786.     if( size($found) > 0 )
  787.     {
  788.         //    connect the object->world matrix of that object
  789.         //    to the ik handle
  790.         //
  791.         connectAttr -f ($value + ".worldMatrix") $plug;
  792.     }
  793.     else
  794.     {
  795.         //    named object is invalid, flag an error
  796.         //
  797.         error( "Object " + $value + " does not exist" );
  798.     }
  799. }
  800.  
  801. proc string getIkWorldUpObject( string $plug )
  802. //
  803. //    Description:
  804. //
  805. //        Given one of the matrix attributes on the ik handle
  806. //        (World Up Object or World Up Object 2), finds the
  807. //        name of the object that is driving that attribute.
  808. //
  809. {
  810.     //    make sure that the attribute actually exists on the
  811.     //    node (remember, these are dynamic attributes)
  812.     //
  813.     string $buf[];
  814.     tokenize( $plug, ".", $buf );
  815.     string $node = $buf[0];
  816.     string $attr = $buf[1];
  817.  
  818.     if( `attributeQuery -ex -n $node $attr` )
  819.     {
  820.         //    find the object connected to the attribute
  821.         //
  822.         string $inputs[] = `listConnections $plug`;
  823.         
  824.         if( size($inputs) > 0 )
  825.         {
  826.             return $inputs[0];
  827.         }
  828.         else
  829.         {
  830.             return "";
  831.         }
  832.     }
  833.     else
  834.     {
  835.         return "";
  836.     }
  837. }
  838.  
  839. global proc updateIkWorldUpObject( string $nodeName, 
  840.                                    string $plug, 
  841.                                    string $worldUpObjectControl )
  842. //
  843. //    Description:
  844. //        
  845. //        Updates the specified text field control for
  846. //        either the World Up Object or World Up Object 2 
  847. //        attribute when the AE shifts focus to another IK handle.
  848. //
  849. {
  850.     //    figure out the currently connected up object
  851.     //
  852.     string $curObject = getIkWorldUpObject( $plug );
  853.  
  854.     //    update the current contents of the text, and the change
  855.     //    callback function
  856.     //
  857.     string $cmd1 = "AEikWorldUpObjectControlProc "+ $plug + " " + $worldUpObjectControl;
  858.     textFieldGrp -e
  859.         -text $curObject
  860.         -cc $cmd1
  861.         $worldUpObjectControl;
  862.     
  863.     //    set the visibility of the text box, based on whether or
  864.     //    not the advanced controls are enabled
  865.     //
  866.     if( `attributeQuery -ex -n $nodeName "dTwistControlEnable"` )
  867.     {
  868.         textFieldGrp -e -vis 1 $worldUpObjectControl;
  869.     }
  870.     else
  871.     {
  872.         textFieldGrp -e -vis 0 $worldUpObjectControl;
  873.     }
  874. }
  875.  
  876. global proc twistControlDimUI( string $nodeName )
  877. //
  878. //    Description:
  879. //
  880. //        Dims UI when the Enable Twist Controls checkbox
  881. //        is enabled/disabled.  This will dim or undim all
  882. //        advanced twist control UI.
  883. //
  884. {
  885.     if( `attributeQuery -ex -n $nodeName "dTwistControlEnable"` )
  886.     {
  887.         int $enable = `getAttr ($nodeName + ".dTwistControlEnable")`;
  888.  
  889.         if( $enable )
  890.         {
  891.             editorTemplate -dimControl $nodeName "dWorldUpType" false;
  892.             editorTemplate -dimControl $nodeName "dWorldUpAxis" false;
  893.             editorTemplate -dimControl $nodeName "dTwistValueType" false;
  894.             worldUpTypeDimUI( $nodeName );
  895.             twistValueTypeDimUI( $nodeName );
  896.         }
  897.         else
  898.         {
  899.             editorTemplate -dimControl $nodeName "twist" false;
  900.             editorTemplate -dimControl $nodeName "twistType" false;
  901.  
  902.             setStateIkWorldUpObject( $nodeName, false, false );
  903.             editorTemplate -dimControl $nodeName "dWorldUpType" true;
  904.             editorTemplate -dimControl $nodeName "dWorldUpAxis" true;
  905.             editorTemplate -dimControl $nodeName "dWorldUpVector" true;
  906.             editorTemplate -dimControl $nodeName "dWorldUpVectorEnd" true;
  907.             editorTemplate -dimControl $nodeName "dTwistValueType" true;
  908.             editorTemplate -dimControl $nodeName "dTwistStartEnd" true;
  909.             editorTemplate -dimControl $nodeName "dTwistRamp" true;
  910.             editorTemplate -dimControl $nodeName "dTwistRampMult" true;
  911.         }
  912.     }
  913. }
  914.  
  915. global proc worldUpTypeDimUI( string $nodeName )
  916. //
  917. //    Description:
  918. //
  919. //        Dims/undims UI when the World Up Type dropdown menu
  920. //        is changed.  The different options in this menu
  921. //        use different attributes for control.
  922. //
  923. {
  924.     if( `attributeQuery -ex -n $nodeName "dWorldUpType"` )
  925.     {
  926.         int $worldUpType = `getAttr ($nodeName + ".dWorldUpType")`;
  927.         if( $worldUpType == 0 )
  928.         {
  929.             // scene up - uses no controls, so dim everything
  930.             //
  931.             editorTemplate -dimControl $nodeName "dWorldUpVector" true;
  932.             editorTemplate -dimControl $nodeName "dWorldUpVectorEnd" true;
  933.             setStateIkWorldUpObject( $nodeName, false, false );
  934.         }
  935.         else if( $worldUpType == 1 )
  936.         {
  937.             // object up - just undim World Up Object
  938.             //
  939.             editorTemplate -dimControl $nodeName "dWorldUpVector" true;
  940.             editorTemplate -dimControl $nodeName "dWorldUpVectorEnd" true;
  941.             setStateIkWorldUpObject( $nodeName, true, false );
  942.         }
  943.         else if( $worldUpType == 2 )
  944.         {
  945.             // object up start,end - undim World Up Object, World Up Object 2
  946.             //
  947.             editorTemplate -dimControl $nodeName "dWorldUpVector" true;
  948.             editorTemplate -dimControl $nodeName "dWorldUpVectorEnd" true;
  949.             setStateIkWorldUpObject( $nodeName, true, true );
  950.         }
  951.         else if( $worldUpType == 3 )
  952.         {
  953.             // object rotation up - just undim World Up Object
  954.             //
  955.             editorTemplate -dimControl $nodeName "dWorldUpVector" false;
  956.             editorTemplate -dimControl $nodeName "dWorldUpVectorEnd" true;
  957.             setStateIkWorldUpObject( $nodeName, true, false );
  958.         }
  959.         else if( $worldUpType == 4 )
  960.         {
  961.             // object rotation up start/end - undim World Up Object, World Up Object 2
  962.             //
  963.             editorTemplate -dimControl $nodeName "dWorldUpVector" false;
  964.             editorTemplate -dimControl $nodeName "dWorldUpVectorEnd" false;
  965.             setStateIkWorldUpObject( $nodeName, true, true );
  966.         }
  967.         else if( $worldUpType == 5 )
  968.         {
  969.             // vector - just undim Up Vector control
  970.             //
  971.             editorTemplate -dimControl $nodeName "dWorldUpVector" false;
  972.             editorTemplate -dimControl $nodeName "dWorldUpVectorEnd" true;
  973.             setStateIkWorldUpObject( $nodeName, false, false );
  974.         }
  975.         else if( $worldUpType == 6 )
  976.         {
  977.             // vector start/end - undim Up Vector and Up Vector 2 controls
  978.             //
  979.             editorTemplate -dimControl $nodeName "dWorldUpVector" false;
  980.             editorTemplate -dimControl $nodeName "dWorldUpVectorEnd" false;
  981.             setStateIkWorldUpObject( $nodeName, false, false );
  982.         }
  983.         else if( $worldUpType == 7 )
  984.         {
  985.             // relative mode - no twist controls, so dim everything
  986.             //
  987.             editorTemplate -dimControl $nodeName "dWorldUpVector" true;
  988.             editorTemplate -dimControl $nodeName "dWorldUpVectorEnd" true;
  989.             setStateIkWorldUpObject( $nodeName, false, false );
  990.         }
  991.     }
  992. }
  993.  
  994. global proc twistValueTypeDimUI( string $nodeName )
  995. //
  996. //    Description:
  997. //
  998. //        Dims/undims UI appropriate to the currently selected
  999. //        Twist Value Type setting.
  1000. //
  1001. {
  1002.     if( `attributeQuery -ex -n $nodeName "dTwistValueType"` )
  1003.     {
  1004.         int $twistValueType = `getAttr ($nodeName + ".dTwistValueType")`;
  1005.  
  1006.         if( $twistValueType == 0 )
  1007.         {
  1008.             // total twist - uses the Twist and Twist Type values
  1009.             //
  1010.             editorTemplate -dimControl $nodeName "twist" false;
  1011.             editorTemplate -dimControl $nodeName "twistType" false;
  1012.             editorTemplate -dimControl $nodeName "dTwistStartEnd" true;
  1013.             editorTemplate -dimControl $nodeName "dTwistRamp" true;
  1014.             editorTemplate -dimControl $nodeName "dTwistRampMult" true;
  1015.         }
  1016.         else if( $twistValueType == 1 )
  1017.         {
  1018.             // start/end twist - uses Type Type and Start/End Twist
  1019.             // controls
  1020.             editorTemplate -dimControl $nodeName "twist" true;
  1021.             editorTemplate -dimControl $nodeName "twistType" false;
  1022.             editorTemplate -dimControl $nodeName "dTwistStartEnd" false;
  1023.             editorTemplate -dimControl $nodeName "dTwistRamp" true;
  1024.             editorTemplate -dimControl $nodeName "dTwistRampMult" true;
  1025.         }
  1026.         else if( $twistValueType == 2 )
  1027.         {
  1028.             // ramp - just uses the Twist Ramp and Twist Ramp Multiplier
  1029.             // controls.
  1030.             editorTemplate -dimControl $nodeName "twist" true;
  1031.             editorTemplate -dimControl $nodeName "twistType" true;
  1032.             editorTemplate -dimControl $nodeName "dTwistStartEnd" true;
  1033.             editorTemplate -dimControl $nodeName "dTwistRamp" false;
  1034.             editorTemplate -dimControl $nodeName "dTwistRampMult" false;
  1035.         }
  1036.  
  1037.     }
  1038. }
  1039.  
  1040. global proc setStateIkWorldUpObject( string $nodeName, 
  1041.                                      int $state1, 
  1042.                                      int $state2 )
  1043. //
  1044. //    Description:
  1045. //
  1046. //        Sets the dimmed state of the World Up Object and
  1047. //        World Up Object 2 controls for the specified node.
  1048. //
  1049. {
  1050.     //    use these arrays to find any existing UI that 
  1051.     //    refers to the specified node
  1052.     //
  1053.     global string $gAEikWorldUpWidgets[];
  1054.     global string $gAEikWorldUp2Widgets[];
  1055.  
  1056.     int $vis = 1;
  1057.     if( !`attributeQuery -ex -n $nodeName "dTwistControlEnable"` )
  1058.     {
  1059.         $vis = 0;
  1060.     }
  1061.  
  1062.     //    Update the world up object text field for all attribute
  1063.     //    editors looking at this node
  1064.     //
  1065.     int $i;
  1066.     for ($i = 0; $i < size($gAEikWorldUpWidgets); $i += 3 )
  1067.     {
  1068.         if ( $nodeName == $gAEikWorldUpWidgets[$i] ) 
  1069.         {
  1070.             string $worldUpObjectControl = $gAEikWorldUpWidgets[$i+2];
  1071.             if ( `textFieldGrp -exists $worldUpObjectControl` )
  1072.             {
  1073.                 textFieldGrp -e -vis $vis $worldUpObjectControl;
  1074.                 textFieldGrp -e -enable $state1 $worldUpObjectControl;
  1075.             }
  1076.         }
  1077.     }
  1078.  
  1079.     //    Update the world up object 2 text field for all attribute
  1080.     //    editors looking at this node
  1081.     //
  1082.     for ($i = 0; $i < size($gAEikWorldUp2Widgets); $i += 3 )
  1083.     {
  1084.         if ( $nodeName == $gAEikWorldUp2Widgets[$i] ) 
  1085.         {
  1086.             string $worldUpObjectControl = $gAEikWorldUp2Widgets[$i+2];
  1087.             if ( `textFieldGrp -exists $worldUpObjectControl` )
  1088.             {
  1089.                 textFieldGrp -e -vis $vis $worldUpObjectControl;
  1090.                 textFieldGrp -e -enable $state2 $worldUpObjectControl;
  1091.             }
  1092.         }
  1093.     }
  1094. }
  1095. //=====================================================================
  1096. //    End Part 3.
  1097. //=====================================================================
  1098.  
  1099.  
  1100. global proc AEikHandleTemplate( string $nodeName )
  1101. {
  1102.  
  1103.     editorTemplate -beginScrollLayout;
  1104.  
  1105.         // include/call base class/node attributes
  1106.         AEtransformMain($nodeName);
  1107.     
  1108.         editorTemplate -beginLayout "Skeleton Info" -collapse false;
  1109.             editorTemplate -addControl "startJoint";
  1110.             editorTemplate -addControl "endEffector";
  1111.         editorTemplate -endLayout;
  1112.  
  1113.         editorTemplate -beginLayout "IK Handle Attributes";
  1114.             editorTemplate -addControl "snapEnable";
  1115.             editorTemplate -addControl "stickiness";
  1116.             editorTemplate -addSeparator;
  1117.             editorTemplate -addControl "priority";
  1118.             editorTemplate -addControl "weight";
  1119.             editorTemplate -addControl "poWeight";
  1120.         editorTemplate -endLayout;
  1121.  
  1122.         editorTemplate -beginLayout "IK Solver Attributes";
  1123.             editorTemplate -addControl "ikBlend"
  1124.                         "checkIkHandleSolverEnable";
  1125.             editorTemplate -label "Ik Fk Control" -addControl "ikFkManipulation" "checkIKHandleIKBlendEnable";
  1126.             editorTemplate -callCustom "AEikHandleSolverNew"
  1127.                         "AEikHandleSolverReplace"
  1128.                         "ikSolver";
  1129.  
  1130.             editorTemplate -addSeparator;
  1131.  
  1132.             editorTemplate -addControl "poleVector";
  1133.             editorTemplate -addControl "offset";
  1134.             editorTemplate -addControl "roll";
  1135.             editorTemplate -addControl "twist";
  1136.             editorTemplate -addControl "twistType";
  1137.             editorTemplate -beginNoOptimize;
  1138.             editorTemplate -addControl "rootOnCurve";
  1139.             editorTemplate -addControl "rootTwistMode";
  1140.             editorTemplate -endNoOptimize;
  1141.  
  1142.             editorTemplate -addSeparator;
  1143.  
  1144.             //----------------------------------------------
  1145.             // Advanced Twist Attributes Section
  1146.             //----------------------------------------------
  1147.  
  1148.             // button to add the new twist controls
  1149.             //
  1150.             editorTemplate -callCustom "AEikTwistAddAttrNew"
  1151.                         "AEikTwistAttrReplace"
  1152.                         "";
  1153.             
  1154.             //    control to enable/disable all advanced twist controls
  1155.             //
  1156.             editorTemplate -addDynamicControl -label "Enable Twist Controls" dTwistControlEnable "twistControlDimUI";
  1157.             editorTemplate -addDynamicControl -label "World Up Type" dWorldUpType "worldUpTypeDimUI";
  1158.             editorTemplate -addDynamicControl -label "Up Axis" dWorldUpAxis;
  1159.             editorTemplate -addDynamicControl -label "Up Vector" dWorldUpVector;
  1160.             editorTemplate -addDynamicControl -label "Up Vector 2" dWorldUpVectorEnd;
  1161.  
  1162.             //    World Up Object and World Up Object 2 matrix attributes
  1163.             //    are controlled by these custom text boxes
  1164.             //
  1165.             editorTemplate -callCustom
  1166.                 "AEikWorldUpObjectNew"
  1167.                 "AEikWorldUpObjectReplace"
  1168.                 "dWorldUpMatrix";
  1169.  
  1170.             editorTemplate -callCustom
  1171.                 "AEikWorldUpObject2New"
  1172.                 "AEikWorldUpObject2Replace"
  1173.                 "dWorldUpMatrixEnd";
  1174.  
  1175.             //    suppress display of the matrix attributes, as
  1176.             //    the text boxes provide the UI for them.
  1177.             //
  1178.             editorTemplate -suppress dWorldUpMatrix;
  1179.             editorTemplate -suppress dWorldUpMatrixEnd;
  1180.  
  1181.             //    controls for the twist value type
  1182.             //
  1183.             editorTemplate -addDynamicControl -label "Twist Value Type" dTwistValueType "twistValueTypeDimUI";
  1184.             editorTemplate -addDynamicControl -label "Start/End Twist" dTwistStartEnd;
  1185.             editorTemplate -addDynamicControl -label "Twist Ramp" dTwistRamp;
  1186.             editorTemplate -addDynamicControl -label "Twist Ramp Multiplier" dTwistRampMult;
  1187.  
  1188.             editorTemplate -addSeparator;
  1189.             //----------------------------------------------
  1190.             //    End of Advanced Twist Controls section
  1191.             //----------------------------------------------
  1192.  
  1193.         editorTemplate -endLayout;
  1194.     
  1195.         // include/call base class/node attributes
  1196.         AEtransformNoScroll($nodeName);
  1197.  
  1198.         // supressed attributes
  1199.         editorTemplate -suppress "ikSolver";
  1200.         editorTemplate -suppress "handlePlaybackSolve";
  1201.         editorTemplate -suppress "inCurve";
  1202.         editorTemplate -suppress "rootTwistMode";
  1203.  
  1204.     editorTemplate -addExtraControls;
  1205.     editorTemplate -endScrollLayout;
  1206.  
  1207. }
  1208.